package com.example.spring.activemq.jms.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@ApiModel(
        description = "公共返回对象"
)
public class MQRstData<T> implements Serializable {
    private static final Logger log = LoggerFactory.getLogger(MQRstData.class);
    @ApiModelProperty(
            value = "发送类型（1-拉单、2-下发、3-物流、4-订单状态更新、5-库存更新、6-操作履历、7-退单等）",
            dataType = "String"
    )
    private Integer type;
    @ApiModelProperty(
            value = "操作类型（1-新增、2-修改、3-删除等）",
            dataType = "String"
    )
    private Integer opertionType;
    @ApiModelProperty(
            value = "状态码标识",
            dataType = "String"
    )
    private String code;
    @ApiModelProperty(
            value = "业务信息",
            dataType = "String"
    )
    private String msg;
    @ApiModelProperty(
            value = "结果集(泛型)",
            required = true,
            dataType = "object"
    )
    private T result;
    @ApiModelProperty(
            value = "表名称后缀",
            dataType = "String"
    )
    private String tableSubfix;

    private MQRstData() {
    }

    public static MQRstData getInstance() {
        MQRstData rstData = new MQRstData();
        return rstData;
    }

    public static MQRstData successMsg(String msg) {
        MQRstData rstData = getInstance();
        rstData.setCode(EnumResult.SUCCESS.getCode());
        rstData.setMsg(msg);
        return rstData;
    }

    public static MQRstData successMsg(String msg, Object obj) {
        MQRstData rstData = getInstance();
        rstData.setCode(EnumResult.SUCCESS.getCode());
        rstData.setMsg(msg);
        rstData.setResult(obj);
        return rstData;
    }

    public static MQRstData successMsg(String msg, String key, Object value) {
        Map<String, Object> map = new HashMap();
        map.put(key, value);
        MQRstData rstData = getInstance();
        rstData.setCode(EnumResult.SUCCESS.getCode());
        rstData.setMsg(msg);
        rstData.setResult(map);
        return rstData;
    }

    public MQRstData(Integer type, Integer opertionType, String code, String msg, T result, String tableSubfix) {
        this.type = type;
        this.opertionType = opertionType;
        this.code = code;
        this.msg = msg;
        this.result = result;
        this.tableSubfix = tableSubfix;
    }

    public MQRstData(Integer type, Integer opertionType, T result, String tableSubfix) {
        this.type = type;
        this.opertionType = opertionType;
        this.code = this.code;
        this.msg = this.msg;
        this.result = result;
        this.tableSubfix = tableSubfix;
    }

    public T getResult() {
        return this.result;
    }

    public static MQRstData success() {
        return successMsg(EnumResult.SUCCESS.getMsg());
    }

    public static MQRstData success(Object obj) {
        return successMsg(EnumResult.SUCCESS.getMsg(), obj);
    }

    public static MQRstData success(String key, Object value) {
        return successMsg(EnumResult.SUCCESS.getMsg(), key, value);
    }

    private static MQRstData faild(String code, String msg) {
        MQRstData rstData = new MQRstData();
        rstData.setCode(code);
        rstData.setMsg(msg);
        return rstData;
    }

    public static MQRstData faild(EnumInfoType eit) {
        return faild(eit.getCode(), eit.getMsg());
    }

    public static MQRstData faild(EnumInfoType er, String msg) {
        return faild(er.getCode(), er.getMsg() + "，具体原因：" + msg);
    }

    public static MQRstData faild(ExceptionInfoType eit) {
        return faild(eit.getCode(), eit.getMsg());
    }

    public static MQRstData faild(String msg) {
        return faild((EnumInfoType) EnumResult.FAILED, msg);
    }

    public Integer getType() {
        return this.type;
    }

    public Integer getOpertionType() {
        return this.opertionType;
    }

    public String getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public String getTableSubfix() {
        return this.tableSubfix;
    }

    public void setType(final Integer type) {
        this.type = type;
    }

    public void setOpertionType(final Integer opertionType) {
        this.opertionType = opertionType;
    }

    public void setCode(final String code) {
        this.code = code;
    }

    public void setMsg(final String msg) {
        this.msg = msg;
    }

    public void setResult(final T result) {
        this.result = result;
    }

    public void setTableSubfix(final String tableSubfix) {
        this.tableSubfix = tableSubfix;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof MQRstData)) {
            return false;
        } else {
            MQRstData<?> other = (MQRstData) o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                Object this$type = this.getType();
                Object other$type = other.getType();
                if (this$type == null) {
                    if (other$type != null) {
                        return false;
                    }
                } else if (!this$type.equals(other$type)) {
                    return false;
                }

                Object this$opertionType = this.getOpertionType();
                Object other$opertionType = other.getOpertionType();
                if (this$opertionType == null) {
                    if (other$opertionType != null) {
                        return false;
                    }
                } else if (!this$opertionType.equals(other$opertionType)) {
                    return false;
                }

                Object this$code = this.getCode();
                Object other$code = other.getCode();
                if (this$code == null) {
                    if (other$code != null) {
                        return false;
                    }
                } else if (!this$code.equals(other$code)) {
                    return false;
                }

                label62:
                {
                    Object this$msg = this.getMsg();
                    Object other$msg = other.getMsg();
                    if (this$msg == null) {
                        if (other$msg == null) {
                            break label62;
                        }
                    } else if (this$msg.equals(other$msg)) {
                        break label62;
                    }

                    return false;
                }

                label55:
                {
                    Object this$result = this.getResult();
                    Object other$result = other.getResult();
                    if (this$result == null) {
                        if (other$result == null) {
                            break label55;
                        }
                    } else if (this$result.equals(other$result)) {
                        break label55;
                    }

                    return false;
                }

                Object this$tableSubfix = this.getTableSubfix();
                Object other$tableSubfix = other.getTableSubfix();
                if (this$tableSubfix == null) {
                    if (other$tableSubfix != null) {
                        return false;
                    }
                } else if (!this$tableSubfix.equals(other$tableSubfix)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof MQRstData;
    }

    public int hashCode() {
        int result = 1;
        Object $type = this.getType();
        Object $opertionType = this.getOpertionType();
        result = result * 59 + ($opertionType == null ? 43 : $opertionType.hashCode());
        Object $code = this.getCode();
        result = result * 59 + ($code == null ? 43 : $code.hashCode());
        Object $msg = this.getMsg();
        result = result * 59 + ($msg == null ? 43 : $msg.hashCode());
        Object $result = this.getResult();
        result = result * 59 + ($result == null ? 43 : $result.hashCode());
        Object $tableSubfix = this.getTableSubfix();
        result = result * 59 + ($tableSubfix == null ? 43 : $tableSubfix.hashCode());
        return result;
    }

    public String toString() {
        return "MQRstData(type=" + this.getType() + ", opertionType=" + this.getOpertionType() + ", code=" + this.getCode() + ", msg=" + this.getMsg() + ", result=" + this.getResult() + ", tableSubfix=" + this.getTableSubfix() + ")";
    }
}
